import QtQuick 1.1
import com.nokia.meego 1.0

PageTemplate {
    id: toolsPage

    CaptionItem {
        id: captionItem
        Row {
            id: editButtons
            parent: captionItem.captionContentRow
            width: captionItem.captionContentRow.width
            height: captionItem.height
            Label {
                id: captionText
                width: editButtons.width
                height: captionItem.height
                color: theme.inverted ? '#ffffff' : '#000000'
                font.weight: Font.Normal
                elide: Text.ElideLeft
                verticalAlignment: Text.AlignVCenter
                text: appWindow.captionText
            }
        }
    }

    VisualDataModel {
        id: toolsVisualModel
        model: ListModel {
            id: toolsModel
            ListElement {
                type: "new"
                title: "New"
                subtitle: "Create empty text file"
                section: "File"
            }
            ListElement {
                type: "open"
                title: "Open"
                subtitle: "Load text from a file"
                section: "File"
            }
            ListElement {
                type: "recent"
                title: "Recent"
                subtitle: "Reopen a recent text file"
                section: "File"
            }
            ListElement {
                type: "save"
                title: "Save"
                subtitle: "Save text to a file"
                section: "File"
            }
            /*
            ListElement {
                type: "settings"
                title: "Settings"
                subtitle: "Configure application settings"
                section: "Config"
            }
            ListElement {
                type: "about"
                title: "About"
                subtitle: "About the application"
                section: "Config"
            }
            */
        }
        delegate: InfoItemDelegate {
            id: toolsDelegate
            Column {
                id: listItemContent
                Label {
                    text: title
                    font.weight: Font.Bold
                    font.pointSize: 16
                }
                Label {
                    text: subtitle
                    font.weight: Font.Light
                    font.pointSize: 16
                }
            }
            onItemClicked: {
                if (type === 'new' || type === 'open' || type === 'save') {
                    toolsPage.loadFileSystemPage(type);
                } else if (type === 'recent') {
                    var p = appWindow.loadFile('RecentPage.qml');
                    if (p !== null) {
                        appWindow.pageStack.push(p);
                    }
                }
            }
        }
    }

    InfoItemView {
        id: toolsListView
        anchors {
            left: parent.left
            right: parent.right
            bottom: parent.bottom
            top: parent.top
            topMargin: captionItem.height
        }
        model: toolsVisualModel
        section.property: "section"
    }

    ScrollDecorator {
        flickableItem: toolsListView
    }

    function loadFileSystemPage(type) {
        var p = appWindow.loadFile('FileSystemPage.qml');
        if (p !== null) {
            appWindow.pageStack.push(p);
            p.setType(type);
        }
    }

    Component.onCompleted: {
        console.log("ToolsPage.onCompleted")
    }

    Component.onDestruction: {
        console.log("ToolsPage.onDestruction")
    }
}
